package com.com.typhoon.controller;

import com.com.typhoon.entity.User;
import com.com.typhoon.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/23 下午2:23
 * @description
 * @modified by
 * @since V2.0.0
 */
@Controller
public class ExportController {

    @Autowired
    private UserService userService;

    /**
     * Handle request to download an Excel document
     */
    @GetMapping("/views")
    public String getUsers(ModelMap model) {
        model.addAttribute("users", userService.findAllUsers());
        return "views";
    }

    @GetMapping("/hello.json")
    @ResponseBody
    public String hello() {
        return "hello";
    }

    @RequestMapping(
            value = "/users/{id}",
            produces = { "application/json", "application/xml" },
            method = RequestMethod.GET)
    public @ResponseBody User getUserById(@PathVariable(value = "id") long id) {
        return userService.getById(id);
    }

    @RequestMapping(value = "/test1")
    @ResponseBody
    public String test1(){
        return "method test1";
    }

//    @RequestMapping(value = "/test1")
//    @ResponseBody
//    public String test2(){
//        return "method test2";
//    }


}
